var showUnkownUserByRole, 					//获取为分配指定角色用户
	getValues, 										//获取传入的角色id和所属公司id
	saveRoleUser;									//保存角色用户关系
require(['grid'], function () {
	//初始化弹出层为设置指定角色未对应的用户列表
	var $selUserList = $("#selUserList");
	$selUserList.grid({
		url : "/sysRole/getUnkownUserPageByUserRoleVo.htm",
		colModel:[{name: "id", index: "id", label:"id", key: true, hidden: true},
			{name: "acctName", index: "acctName", label:"用户账号", sorttype: "text",align: "left", width:80},
			{name: "name", index: "name", label:"用户名称", sorttype: "text",align: "left", width:80},
			{name: "organName", index: "organName", label:"所属机构", sorttype: "text",align: "center", width:120},
			{name: "remark", index: "remark", label:"备注", sorttype: "text",align: "left"}],
		width:865,
		height:315
	});

	//弹出对话框的用户名搜索
	$("#searchNameBtn").click(function(){
		//var roleId = $("#id").val();
		showUnkownUserByRole($("#searchName").val());
	});
				
	getValues = function(_id, _corpId){
		id = _id;
		corpId = _corpId;
	};

	/**
	 * 显示列表角色对应未配置的用户列表
	 * @param acctName 查询关键字
	 */
	showUnkownUserByRole = function(acctName){
		$selUserList.jqGrid('setGridParam', {page:1,datatype:"json",postData:{roleId:id,acctName:acctName,corpId:corpId}}).trigger("reloadGrid");
	};
	
	/**
	 * 保存角色用户关系
	 */
	saveRoleUser = function(roleId, $userlist){
		//保存动作
		var userIds = $("#selUserList").jqGrid('getGridParam','selarrrow');//获取选择的用户id
		$.ajaxExt({
			url:"/sysRole/saveUserRole.htm",
			data:{
				"userIds":userIds,
				"roleId":roleId
			}
		}).done(function(){
			$.messager.alert("提示","保存成功!","info");//保存提示
			$userlist.grid('setGridParam', {page:1,datatype:"json",postData:{roleId:roleId,corpId:corpId}}).trigger("reloadGrid");//显示角色对应的用户列表
		});
	}
});
